<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 活动基本信息
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <el-table
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        header-cell-class-name="table-header"



        handleDelete(index){//可以使用但是不太好
        // deleteactivityinfo(row.activity_id).then(res=>{
        //     console.log(res)
        //     if (res.data.msg == "删除成功") {
        //   this.$alert("《" + row.activity_id + "》确定删除！", "消息", {
        //     confirmButtonText: "确定",
        //     callback: action => {// eslint-disable-line no-unused-vars
        //       window.location.reload();
        //     }
        //   });
        // }
        // })

         this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
         
         deleteactivityinfo(index.activity_id).then(res=>{
             console.log(res)
         })
        //   this.tableData.splice(index, 1);
          this.$message({
            type: "success",
            message: "删除成功！"
            
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除失败"
          });
        });
       console.log(index)

    },

      >
        <el-table-column fixed prop="activity_id" label="活动编号" width="80"></el-table-column>
        <el-table-column prop="activity_type_name" label="活动类型名" width="100"></el-table-column>
        <el-table-column prop="activity_name" label="活动名" width="100"></el-table-column>
        <el-table-column prop="activity_description" label="活动描述" width="300"></el-table-column>
        <el-table-column fixed prop="activity_start_time" label="活动开始时间" width="80"></el-table-column>
        <el-table-column prop="activity_end_time" label="活动结束时间" width="100"></el-table-column>
        <el-table-column prop="signup_start_time" label="活动报名开始时间" width="100"></el-table-column>
        <el-table-column prop="signup_end_time" label="活动报名结束时间" width="100"></el-table-column>
        <el-table-column fixed prop="times" label="时间年" width="80"></el-table-column>
        <el-table-column prop="x_coordinate" label="活动地点x坐标" width="100"></el-table-column>
        <el-table-column prop="y_coordinate" label="活动地点y坐标" width="100"></el-table-column>
        <el-table-column prop="activity_place" label="活动地点" width="100"></el-table-column>

        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button
              type="text"
              icon="el-icon-delete"
              class="red"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 编辑弹出框 -->
    <el-dialog title="编辑" v-model="editVisible" width="30%">
      <el-form ref="form" :model="form" label-width="70px">
        <el-form-item label="活动编号">
          <el-input v-model="form.activity_id" readonly></el-input>
        </el-form-item>
        <el-form-item label="活动名字">
          <el-input v-model="form.activity_name"></el-input>
        </el-form-item>
        <el-form-item label="活动描述" prop="activity_description">
          <el-input v-model="form.activity_description"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveEdit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { activityinfolist } from "../api/index";
//updateactivityinfo
import { updateactivityinfo } from "../api/index";
// import { deleteactivityinfo } from "../api/index";
import axios from "axios";

export default {
  name: "activityinfo",
  data() {
    return {
      list: [],
      tableData: [],
      multipleSelection: [],
      delList: [],
      editVisible: false,
      form: {
        activity_id: "",
        activity_type_name: "",
        activity_name: "",
        activity_description: "",
        activity_start_time: "",
        activity_end_time: "",
        signup_start_time: "",
        signup_end_time: "",
        x_coordinate: "",
        y_coordinate: "",
        activity_place: ""
      },
      idx: 0,
      id: 0
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 获取 easy-mock 的模拟数据
    getData() {
      activityinfolist().then(res => {
        this.tableData = res.data.list;
      });
    },

    // 删除操作
    handleDelete(row) {
      // console.log(row.activity_id)
      // var qs=require('qs')
      console.log(row + "11" + row.activity_id);
      // console.log(qs.stringify(row.activity_id))
      //  deleteactivityinfo(row.activity_id).then(res=>{
      const _this = this;

      axios({
        method: "put",
        url:
          "http://localhost:8085/tb-activityinfo/web/deleteActivityInfo?activity_id=" +
          row.activity_id
      }).then(function(res) {
        if (res.data.data.msg == "删除成功") {
          _this.$alert("《" + row.activity_id + "》确定删除！", "消息", {
            confirmButtonText: "确定",
            callback: action => {// eslint-disable-line no-unused-vars
              window.location.reload();
            }
          });
        }
      });
    },

    // 编辑操作
    handleEdit(row) {
      // this.idx = index;
      this.form = row;
      updateactivityinfo(this.form).then(res => {
        console.log(res);

        if (res.data.msg == "活动信息修改成功") {
          this.$alert("《" + this.form.activity_id + "》修改成功！", "消息", {
            confirmButtonText: "确定",
            callback: action => {// eslint-disable-line no-unused-vars
              window.location.reload();
            }
          });
        }
      });
      this.editVisible = true;
    },
    // 保存编辑
    saveEdit() {
      this.editVisible = false;
    }
  }
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.mr10 {
  margin-right: 10px;
}
.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>
